﻿using ServiceCore.DbContext;
using ServiceCore.Entity.Core;
using ServiceCore.Entity.Model;

namespace ServiceCore.Service
{
    /// <summary>
    /// 数据服务
    /// </summary>
    public partial class RecordService : SqlsugarServices<RecordInfo>
    {
        public BaseParam<RecordInfo, long> Record_Save_Common_Verify(BaseParam<RecordInfo, long> arg)
        {
            if (arg == null)
                return new BaseParam<RecordInfo, long>("参数不能为空");
            if (arg.Param == null)
                return new BaseParam<RecordInfo, long>("参数不能为空");
            if (arg.Param.DataValue == 0)
                return new BaseParam<RecordInfo, long>("值不能为空");

            return arg;
        }

        public BaseParam<RecordInfo, long> Record_Add_Verify(BaseParam<RecordInfo, long> arg)
        {
            arg = Record_Save_Common_Verify(arg);
            if (string.IsNullOrEmpty(arg.ErrorMsg) == false)
                return arg;
            if (arg.Param.TagId == 0)
                return new BaseParam<RecordInfo, long>("标签id不能为空");
            if (arg.Param.SiteId == 0)
                return new BaseParam<RecordInfo, long>("数组id不能为空");
            if (arg.Param.CreateUserId == 0)
                return new BaseParam<RecordInfo, long>("创建人不能为空");

            arg.Param.CreateTime = DateTime.Now;
            return arg;
        }

        public BaseParam<RecordInfo, long> Record_Edit_Verify(BaseParam<RecordInfo, long> arg)
        {
            arg = Record_Save_Common_Verify(arg);
            if (string.IsNullOrEmpty(arg.ErrorMsg) == false)
                return arg;
            if (arg.Param.Id == 0)
                return new BaseParam<RecordInfo, long>("id不能为空");

            return arg;
        }

        public BaseParam<List<RecordInfo>, long> Record_AddList_Verify(BaseParam<List<RecordInfo>, long> arg)
        {
            if (arg == null)
                return new BaseParam<List<RecordInfo>, long>("参数不能为空");
            if (arg.Param == null)
                return new BaseParam<List<RecordInfo>, long>("参数不能为空");
            arg.Param = arg.Param.Where(x => x.DataValue > 0).ToList();
            if (arg.Param.Any() == false)
                return new BaseParam<List<RecordInfo>, long>("参数不能为空");
            if (arg.Param.Where(x => x.SiteId == 0).Any())
                return new BaseParam<List<RecordInfo>, long>("分组id不能为空");
            if (arg.Param.Where(x => x.TagId == 0).Any())
                return new BaseParam<List<RecordInfo>, long>("标签id不能为空");

            var now = DateTime.Now;
            arg.Param.ForEach(x => x.CreateTime = now);

            return arg;
        }


        public BaseParam<RecordInfo, long> Record_Del_Verify(BaseParam<RecordInfo, long> arg)
        {
            if (arg == null)
                return new BaseParam<RecordInfo, long>("参数不能为空");
            if (arg.Id == 0)
                return new BaseParam<RecordInfo, long>("id不能为空");

            return arg;
        }
    }
}
